import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

export default defineConfig({
  server: {
    // proxy: {
    //   "/api": {
    //     target: "http://localhost:8888", // 后端地址
    //     changeOrigin: true,
    // rewrite: (path) => path.replace(/^\/api/, ""),
    //     configure: (proxy, options) => {
    //       proxy.on("proxyReq", (proxyReq, req, res) => {
    //         proxyReq.setHeader(
    //           "Access-Control-Allow-Methods",
    //           "GET, POST, PUT, DELETE"
    //         );
    //       });
    //     },
    //   },
    // },
    fs: {
      allow: [
        process.cwd(),
        // 使用POSIX路径并允许所有子目录
        "/node_modules/.pnpm/element-plus@2.9.5_vue@3.5.13/node_modules/**",
      ],
    },
  },
  resolve: {
    extensions: [".vue", ".ts", ".js", ".json"], // 显式声明扩展名解析顺序
    alias: {
      "@": "/src",
    },
  },
  plugins: [
    vue(),
    AutoImport({
      resolvers: [
        ElementPlusResolver({
          importStyle: "sass", // 启用Sass样式导入
        }),
      ],
    }),
    Components({
      resolvers: [
        ElementPlusResolver({
          importStyle: "sass", // 同步样式解析配置
        }),
      ],
    }),
  ],
});
